package com.xjc.business.controller.schadmin;

import com.xjc.business.entity.po.schadmin.SchAdminLoginPo;
import com.xjc.business.entity.po.schadmin.SchAdminRegisterPo;
import com.xjc.business.entity.vo.schadmin.SchAdminLoginVo;
import com.xjc.business.service.SchoolAdminsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 徐锦程
 * 时间:2025-01-26 14:41
 */
@RestController
@RequestMapping("/sch_admin/user")
public class SchUserController {

    @Autowired
    SchoolAdminsService schoolAdminsService;

    /**
     * 注册
     * @param schAdminRegisterPo 注册信息
     * @return 反馈
     */
    @PostMapping("/register")
    public Result<String> doRegister(@RequestBody(required = false) SchAdminRegisterPo schAdminRegisterPo){
        if (schAdminRegisterPo == null || schAdminRegisterPo.getUsername() == null || schAdminRegisterPo.getPassword() == null || schAdminRegisterPo.getPhone() == null || schAdminRegisterPo.getEmail() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return schoolAdminsService.doRegister(schAdminRegisterPo);
    }

    /**
     * 登录
     * @param schAdminLoginPo 登录参数
     * @return 登录成功返回token，失败返回错误信息
     */
    @PostMapping("/login")
    public Result<SchAdminLoginVo> doLogin(@RequestBody(required = false) SchAdminLoginPo schAdminLoginPo){
        if(schAdminLoginPo == null || schAdminLoginPo.getUsername() == null || schAdminLoginPo.getPassword() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return schoolAdminsService.doLogin(schAdminLoginPo);
    }
}
